package com.solcoo.merchant.util;

import com.android.common.util.StringUtil;

public class CheckUtil {
	private static final int PWD_SIZE = 6;

	public static CheckResult checkLength(String value, int minSize, int maxSize) {
		CheckResult result = new CheckResult();
		if (StringUtil.isBlank(value)) {
			result.sucessed = false;
			result.failMsg = "不能为空";
			return result;
		}
		if (StringUtil.getLength(value) < minSize) {
			result.sucessed = false;
			result.failMsg = "长度不得少于" + minSize + "位";
			return result;
		}
		if (StringUtil.getLength(value) > maxSize) {
			result.sucessed = false;
			result.failMsg = "长度不得大于" + minSize + "位";
			return result;
		}
		return result;
	}

	public static CheckResult checkPwd(String pwd1, String pwd2) {
		CheckResult result = new CheckResult();
		if (StringUtil.getLength(pwd1) < PWD_SIZE) {
			result.sucessed = false;
			result.failMsg = "密码必须不少于6位";
			return result;
		}
		if (!pwd1.equals(pwd2)) {
			result.sucessed = false;
			result.failMsg = "两次输入的密码不一致";
			return result;
		}
		return result;
	}

	public static CheckResult checkPhoneNo(String phoneNo) {
		CheckResult result = new CheckResult();
		if (StringUtil.isBlank(phoneNo)) {
			result.sucessed = false;
			result.failMsg = "请输入手机号";
			return result;
		}
		if (!(StringUtil.isNumeric(phoneNo) && StringUtil.getLength(phoneNo) == 11)) {
			result.sucessed = false;
			result.failMsg = "手机号输入有误，请重新输入";
			return result;
		}
		return result;
	}

	public static CheckResult checkCardNoOrPhoneNo(String value) {
		CheckResult result = new CheckResult();
		if (StringUtil.isBlank(value)) {
			result.sucessed = false;
			result.failMsg = "请输入手机号或者卡号";
			return result;
		}
		if (!StringUtil.isNumeric(value)) {
			result.sucessed = false;
			result.failMsg = "输入有误，请重新输入";
			return result;
		}
		return result;
	}

	public static CheckResult checkLogin(String phoneNo, String pwd) {
		CheckResult result = new CheckResult();
		if (StringUtil.isBlank(phoneNo)) {
			result.sucessed = false;
			result.failMsg = "请输入用户名";
			return result;
		}
		if (StringUtil.getLength(pwd) < PWD_SIZE) {
			result.sucessed = false;
			result.failMsg = "密码必须不少于6位";
			return result;
		}
		return result;
	}

	public static CheckResult checkQrcode(String code) {
		CheckResult result = new CheckResult();
		if (StringUtil.isNotBlank(code) && StringUtil.isNumeric(code)
				&& code.length() == 5) {
			result.sucessed = true;
		} else {
			result.sucessed = false;
		}
		return result;
	}

	public static CheckResult checkMoney(String money) {
		CheckResult result = new CheckResult();
		if (StringUtil.isBlank(money)) {
			result.sucessed = false;
			result.failMsg = "请输入金额";
			return result;
		}
		if (!StringUtil.isMoney(money)) {
			result.sucessed = false;
			result.failMsg = "金额输入有误";
			return result;
		}

		return result;
	}

	public static CheckResult checkExp(String exp) {
		CheckResult result = new CheckResult();
		if (StringUtil.isBlank(exp)) {
			result.sucessed = false;
			result.failMsg = "请输入经验值";
			return result;
		}
		if (!StringUtil.isMoney(exp)) {
			result.sucessed = false;
			result.failMsg = "经验值输入有误";
			return result;
		}

		return result;
	}

	public static CheckResult checkAddLevel(String discountValue,
			String expValue) {
		CheckResult result = new CheckResult();
		if (StringUtil.isBlank(discountValue)) {
			result.sucessed = false;
			result.failMsg = "请输入折扣";
			return result;
		}
		if (StringUtil.isBlank(expValue)) {
			result.sucessed = false;
			result.failMsg = "请输入经验值";
			return result;
		}

		return result;
	}

	public static class CheckResult {

		public boolean sucessed = true;

		public String failMsg = "系统错误,请重试";

		public boolean isSuccess() {
			return sucessed;
		}

	}
}
